﻿package component.fileupload.action;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import component.fileupload.exception.FileUploadException;
import component.fileupload.vo.UploadFileVO;

public interface IFileUploadAction {
	/**
	 * 设置实现类需要的一些参数，如：struts里的form
	 * @param paraMap
	 * @throws FileUploadException 
	 */
	public void setParameter(Map paraMap) throws FileUploadException;
	
	/**
	 * 设置要保存在服务器上的相对路径
	 * @param savePath
	 */
	public void setSaveFilePath(String savePath);
	
	/**
	 * 获取所有上传文件的流
	 * 
	 * @param config
	 * @param request
	 * @param response
	 * @return
	 * @throws FileUploadException
	 */
	public InputStream[] getInputStreams(ServletConfig config, HttpServletRequest request, HttpServletResponse response) throws FileUploadException;
	
	/**
	 * 获取所有上传文件的信息(保存文件前的信息)
	 * 
	 * @param config
	 * @param request
	 * @param response
	 * @return
	 * @throws FileUploadException
	 */
	public UploadFileVO[] getFileInfoArr(ServletConfig config, HttpServletRequest request, HttpServletResponse response) throws FileUploadException;
	
	/**
	 * 上传文件
	 * @param config
	 * @param request
	 * @param response
	 * @throws FileUploadException 
	 * @return
	 */
	public String doUpload(ServletConfig config, HttpServletRequest request, HttpServletResponse response) throws FileUploadException;
	
	/**
	 * 上传文件,处理其它逻辑
	 * @param config
	 * @param request
	 * @param response
	 * @throws FileUploadException 
	 * @return
	 */
	public String doUploadToOther(ServletConfig config, HttpServletRequest request, HttpServletResponse response) throws FileUploadException;
	
	/**
	 * 接收客户端上传的文件
	 * 
	 * @param request
	 * @return
	 */
	public String receiveFile(HttpServletRequest request, HttpServletResponse response, String fileName) throws FileUploadException;
	
	/**
	 * 
	 * 向服务器发送文件,接收的方法为receiveFile
	 * 
	 * 调用：sendFile("D:/test.txt", "http://localhost:8088/fileupload/fileupload", "receiveFile", "客户端上传的文件.txt", "");
	 * 
	 * @param localFile：上传的本地文件，如 D:/test.txt
	 * @param httpUrl：服务器的路径，如 http://localhost:8088/fileupload/fileupload
	 * @param method：服务器端接收的方法
	 * @param saveFileName：保存在服务器的文件名称
	 * @param parameters：传给服务器端的参数
	 * @return
	 */
	public Object sendFile(String localFile, String httpUrl, String method, String saveFileName, String parameters) throws FileUploadException;
	
	/**
	 * 获取所有上传文件的保存路径
	 * @return
	 */
	public String[] getFilePaths();
	
	/**
	 * 获取所有上传文件的详细信息
	 * @return
	 */
	public Map getFileInfos();
	
	/**
	 * 获取上传文件的进度
	 * @param session
	 * @param response
	 * @throws IOException
	 */
	public String getState(HttpSession session, HttpServletResponse response) throws IOException;
	
	/**
	 * 销毁数据
	 */
	public void destroy();
	
	/**
	 * 删除文件
	 * @param servletContext
	 * @param filePath：文件路径
	 * @return
	 * @throws FileUploadException
	 */
	public String doDelete(ServletContext servletContext, String filePath) throws FileUploadException ;
}
